A for
loop termination condition should test the loop counter against an invariant value that does not change during the execution of
the loop. Invariant termination conditions make the program logic easier to understand and maintain.
This rule tracks three types of non-invariant termination conditions:
- When the loop counters are updated in the body of the
for
loop
- When the termination condition depends on a method call
- When the termination condition depends on an object property since such properties could change during the execution of the loop.